<?php
namespace Foam\Model;

use Zend\Db\Adapter\Adapter;
use Zend\Db\ResultSet\ResultSet;
use Zend\Db\TableGateway\AbstractTableGateway;

class NoteTable extends AbstractTableGateway
{
    protected $table ='foam_note';
    
    public function __construct(Adapter $adapter)
    {
        $this->adapter = $adapter;
        $this->resultSetPrototype = new ResultSet();
        $this->resultSetPrototype->setArrayObjectPrototype(new Note());
        $this->initialize();
    }
    
    public function fetchAll()
    {
        $resultSet = $this->select();
        return $resultSet;
    }
    
    public function getNote($id_produit)
    {
        $id_produit  = (int) $id_produit;
        $rowset = $this->select(array('id_produit' => $id_produit));
        $row = $rowset->current();
//        if (!$row) {
//            throw new \Exception("Could not find row $id_produit");
//        }
        return $row;
    }
    
    public function addNote($id_note,$achat,$labo,$qualite,$marketing,$formation,$operation,$rd,$id_produit)
    {
        $data = array(
            'id_note' => $id_note,
            'achat' => $achat,
            'labo' => $labo,
            'qualite' => $qualite,
            'marketing' => $marketing,
            'formation' => $formation,
            'operation' => $operation,
            'rd' => $rd,
            'id_produit' => $id_produit,
        );
        
        $this->insert($data);
    }
    
    public function updateNote($achat,$labo,$qualite,$marketing,$formation,$operation,$rd,$id_produit)
    {
        $data = array(
            'achat' => $achat,
            'labo' => $labo,
            'qualite' => $qualite,
            'marketing' => $marketing,
            'formation' => $formation,
            'operation' => $operation,
            'rd' => $rd,
        );
        
        $this->update($data, array('id_produit' => $id_produit));
    }
    
    public function deleteNote($id_produit)
    {
        $this->delete(array('id_produit' => $id_produit));
    }
}
